package com.example.erp.config;

import java.util.List;
import java.util.function.Function;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.example.erp.entity.Book;
import com.example.erp.service.BookService;

import jakarta.annotation.Resource;

/**
/* 第二种方式，图书查询服务，将查询方法作为函数Bean导出，需在定义AI聊天客户端的时候需要显式地声明
 */
@Configuration
public class BookServiceConfig {

	@Resource
	private BookService bookService;

	/**
	 * 根据书名查询图书的函数Bean
	 */
	@Bean
	Function<String, List<Book>> findBooksByTitle() {
		return title -> bookService.findBooksByTitle(title);
	}
//
////	等价写法
////	@Bean
////	Function<String, List<Book>> findBooksByTitle() {
////	    return new Function<String, List<Book>>() {
////	        @Override
////	        public List<Book> apply(String title) {
////	            return bookService.findBooksByTitle(title);
////	        }
////	    };
////	}
//	
	/**
	 * 根据作者查询图书的函数Bean
	 */
	@Bean
	Function<String, List<Book>> findBooksByAuthor() {
		return author -> bookService.findBooksByAuthor(author);
	}

	/**
	 * 根据分类查询图书的函数Bean
	 */
	@Bean
	Function<String, List<Book>> findBooksByCategory() {
		return category -> bookService.findBooksByCategory(category);
	}

}


